package com.drophair.jspwork.Servlet;

import com.drophair.jspwork.bean.Sqlgoods;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "AddCartServlet", value = "/AddCartServlet")
public class AddCartServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String goodid="";
        goodid=request.getParameter("goodid");
        String goodname="";
        goodname=request.getParameter("goodname");
        System.out.println("doGet+++++GOODID是："+goodid+"~~~~~ GOODNAME是："+goodname);
        Sqlgoods sqlgoods=new Sqlgoods();
        boolean getSign=false;
        try {
            getSign=sqlgoods.addCart(goodid,goodname);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        if(getSign==true){
            System.out.println("加购成功");
        }
        request.getRequestDispatcher("/common/cart.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String goodid="";
        goodid=request.getParameter("goodid");
        System.out.println("doPost+++++GOODID是："+goodid);

    }
}
